import { defineStore } from 'pinia'
import { store } from '@/store'
import { getAreaTree } from '@/api/system/area'

export interface CustomerState {
  areaOptions: any[] // 这里可以根据实际类型定义更具体的类型
}

export const useCustomerStore = defineStore({
  id: 'customer',
  state: (): CustomerState => ({
    areaOptions: []
  }),
  actions: {
    // 加载地区数据
    async loadAreaData() {
      if (this.areaOptions.length === 0) {
        const res = await getAreaTree()
        this.areaOptions = res
      }
      return this.areaOptions
    }
  }
})

// 设置 store
export function useCustomerStoreWithOut() {
  return useCustomerStore(store)
}

